package top.yuan67.demo;

import cloud.tianai.captcha.common.constant.CaptchaTypeConstant;
import cloud.tianai.captcha.generator.common.constant.SliderCaptchaConstant;
import cloud.tianai.captcha.generator.impl.StandardSliderImageCaptchaGenerator;
import cloud.tianai.captcha.generator.impl.StandardWordOrderClickImageCaptchaGenerator;
import cloud.tianai.captcha.resource.common.model.dto.Resource;
import cloud.tianai.captcha.resource.common.model.dto.ResourceMap;
import cloud.tianai.captcha.resource.impl.DefaultResourceStore;
import cloud.tianai.captcha.resource.impl.provider.ClassPathResourceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import static cloud.tianai.captcha.generator.impl.StandardSliderImageCaptchaGenerator.DEFAULT_SLIDER_IMAGE_TEMPLATE_PATH;

/**
 * @Author: NieQiang
 * @User: CAPTAIN
 * @CreateTime: 2023-7-12
 * @Desc: 验证码资源
 **/
@Component
public class CaptchaResource extends DefaultResourceStore {
  private static final Logger log = LoggerFactory.getLogger(CaptchaResource.class);
  public CaptchaResource() {
    
    // 滑块验证码 模板 (系统内置)
    ResourceMap templateSlider = new ResourceMap(4);
    
    templateSlider.put(SliderCaptchaConstant.TEMPLATE_ACTIVE_IMAGE_NAME,
        new Resource(ClassPathResourceProvider.NAME, DEFAULT_SLIDER_IMAGE_TEMPLATE_PATH.concat("/1/active.png")));
    
    templateSlider.put(SliderCaptchaConstant.TEMPLATE_FIXED_IMAGE_NAME,
        new Resource(ClassPathResourceProvider.NAME, DEFAULT_SLIDER_IMAGE_TEMPLATE_PATH.concat("/1/fixed.png")));
    // 旋转验证码 模板 (系统内置)
    ResourceMap templateRotate = new ResourceMap(4);
    
    templateRotate.put(SliderCaptchaConstant.TEMPLATE_ACTIVE_IMAGE_NAME,
        new Resource(ClassPathResourceProvider.NAME, StandardSliderImageCaptchaGenerator.DEFAULT_SLIDER_IMAGE_TEMPLATE_PATH.concat("/3/active.png")));
    templateRotate.put(SliderCaptchaConstant.TEMPLATE_FIXED_IMAGE_NAME,
        new Resource(ClassPathResourceProvider.NAME, StandardSliderImageCaptchaGenerator.DEFAULT_SLIDER_IMAGE_TEMPLATE_PATH.concat("/3/fixed.png")));
    
    // 1. 添加一些模板
    addTemplate(CaptchaTypeConstant.SLIDER, templateSlider);
    addTemplate(CaptchaTypeConstant.ROTATE, templateRotate);
  
    addTemplate(CaptchaTypeConstant.WORD_ORDER_IMAGE_CLICK,
        StandardWordOrderClickImageCaptchaGenerator.wordToResourceMap("湖北省图", "default"));
    addTemplate(CaptchaTypeConstant.WORD_ORDER_IMAGE_CLICK,
        StandardWordOrderClickImageCaptchaGenerator.wordToResourceMap("汗牛充栋", "default"));
    addTemplate(CaptchaTypeConstant.WORD_ORDER_IMAGE_CLICK,
        StandardWordOrderClickImageCaptchaGenerator.wordToResourceMap("博学多闻", "default"));
    addTemplate(CaptchaTypeConstant.WORD_ORDER_IMAGE_CLICK,
        StandardWordOrderClickImageCaptchaGenerator.wordToResourceMap("手不释卷", "default"));
    addTemplate(CaptchaTypeConstant.WORD_ORDER_IMAGE_CLICK,
        StandardWordOrderClickImageCaptchaGenerator.wordToResourceMap("博览群书", "default"));
  
    
    // 2. 添加自定义背景图片
    addResource(CaptchaTypeConstant.SLIDER, new Resource("classpath", "bgImages/1.png"));
    addResource(CaptchaTypeConstant.SLIDER, new Resource("classpath", "bgImages/2.png"));
    addResource(CaptchaTypeConstant.SLIDER, new Resource("classpath", "bgImages/3.png"));
    addResource(CaptchaTypeConstant.SLIDER, new Resource("classpath", "bgImages/4.png"));
    addResource(CaptchaTypeConstant.SLIDER, new Resource("classpath", "bgImages/5.png"));
    addResource(CaptchaTypeConstant.SLIDER, new Resource("classpath", "bgImages/6.png"));
    
    addResource(CaptchaTypeConstant.CONCAT, new Resource("classpath", "bgImages/1.png"));
    addResource(CaptchaTypeConstant.CONCAT, new Resource("classpath", "bgImages/2.png"));
    addResource(CaptchaTypeConstant.CONCAT, new Resource("classpath", "bgImages/3.png"));
    addResource(CaptchaTypeConstant.CONCAT, new Resource("classpath", "bgImages/4.png"));
    addResource(CaptchaTypeConstant.CONCAT, new Resource("classpath", "bgImages/5.png"));
    addResource(CaptchaTypeConstant.CONCAT, new Resource("classpath", "bgImages/6.png"));
    
    addResource(CaptchaTypeConstant.ROTATE_DEGREE,
        new Resource("classpath", "bgImages/rotate_degree/1.png"));
    addResource(CaptchaTypeConstant.ROTATE_DEGREE,
        new Resource("classpath", "bgImages/rotate_degree/2.png"));
    addResource(CaptchaTypeConstant.ROTATE_DEGREE,
        new Resource("classpath", "bgImages/rotate_degree/3.png"));
    addResource(CaptchaTypeConstant.ROTATE_DEGREE,
        new Resource("classpath", "bgImages/rotate_degree/4.png"));
  
  
    addResource(CaptchaTypeConstant.ROTATE, new Resource("classpath", "bgImages/1.png"));
    addResource(CaptchaTypeConstant.ROTATE, new Resource("classpath", "bgImages/2.png"));
    addResource(CaptchaTypeConstant.ROTATE, new Resource("classpath", "bgImages/3.png"));
    addResource(CaptchaTypeConstant.ROTATE, new Resource("classpath", "bgImages/4.png"));
    addResource(CaptchaTypeConstant.ROTATE, new Resource("classpath", "bgImages/5.png"));
    addResource(CaptchaTypeConstant.ROTATE, new Resource("classpath", "bgImages/6.png"));
  
  
    addResource(CaptchaTypeConstant.WORD_ORDER_IMAGE_CLICK, new Resource("classpath", "bgImages/1.png"));
    addResource(CaptchaTypeConstant.WORD_ORDER_IMAGE_CLICK, new Resource("classpath", "bgImages/2.png"));
    addResource(CaptchaTypeConstant.WORD_ORDER_IMAGE_CLICK, new Resource("classpath", "bgImages/3.png"));
    addResource(CaptchaTypeConstant.WORD_ORDER_IMAGE_CLICK, new Resource("classpath", "bgImages/4.png"));
    addResource(CaptchaTypeConstant.WORD_ORDER_IMAGE_CLICK, new Resource("classpath", "bgImages/5.png"));
    addResource(CaptchaTypeConstant.WORD_ORDER_IMAGE_CLICK, new Resource("classpath", "bgImages/6.png"));
  }
}
